<?php

/* Load the core theme framework. */
require_once( trailingslashit( TEMPLATEPATH ) . 'library/hybrid.php' );
$theme = new Hybrid();	
	
/* Load the theme-options framework. */
require_once( trailingslashit( TEMPLATEPATH ) . 'includes/includes.php' );
$includes = new CVIncludes();

/* Do theme setup on the 'after_setup_theme' hook. */
add_action( 'after_setup_theme', 'theme_setup');

/**
 * Theme setup function.  This function adds support for theme features and defines the default theme
 * actions and filters.
 */
function theme_setup() {
	
	/* Get action/filter hook prefix. */
	$prefix = hybrid_get_prefix();
	
	define('CV_OPTIONS', 'cv_'. $prefix . '_options'); //name of entry into database - will break DB if this has spaces!
	define('CV_BACKUPS', 'cv_'. $prefix . '_backups'); //name of entry into database - will break DB if this has spaces!
	

	/* Add theme support for core framework features. */
	add_theme_support( 'hybrid-core-menus', array( 'primary', 'secondary') );
	//add_theme_support( 'hybrid-core-sidebars', array( 'primary') );
	add_theme_support( 'hybrid-core-widgets' );
	add_theme_support( 'hybrid-core-shortcodes' );
	add_theme_support( 'hybrid-core-post-meta-box' );
	//add_theme_support( 'hybrid-core-drop-downs' );
	//add_theme_support( 'hybrid-core-template-hierarchy' );

	/* Add theme support for framework extensions. */
//	add_theme_support( 'post-stylesheets' );
//	add_theme_support( 'dev-stylesheet' );
//	add_theme_support( 'loop-pagination' );
	add_theme_support( 'get-the-image' );
	add_theme_support( 'breadcrumb-trail' );
//	add_theme_support( 'cleaner-gallery' );

	add_theme_support( 'cvincludes-options');	
	add_theme_support( 'cvincludes-shortcode' );
	add_theme_support( 'cvincludes-socialmedia');
	add_theme_support( 'cvincludes-dropdowns', array('longsubs') );	
	add_theme_support( 'cvincludes-portfolio', array('portfolio_type'=>'filterable'));
	add_theme_support( 'cvincludes-eztables' );
//	add_theme_support( 'cvincludes-layerslider' );


	add_theme_support( 'cvincludes-seo' );	
	$data = get_option(CV_OPTIONS);
	if($data['seo_enable_seo'] == true)
		add_theme_support( 'hybrid-core-seo' );			
	else {
		remove_theme_support( 'hybrid-core-seo' );	
	}	

	/* Add theme support for WordPress features. */
	add_theme_support( 'automatic-feed-links' );	
		
	/* Add the breadcrumb trail just after the container is open. */
	add_action( "{$prefix}_open_main", 'breadcrumb_trail' );
	
	/* Register sidebars. */
	add_action( 'init', 'theme_register_sidebars', 11 );

	/* Filter the breadcrumb trail arguments. */
	add_filter( 'breadcrumb_trail_args', 'breadcrumb_trail_args' );	
	
	add_image_size( 'trending-1-thumb', 320, 140, true);		
	add_image_size( 'entry-image-thumb', 140, 85, true);	
	
	add_image_size( 'popular-image-thumb', 110, 70, true);
	
	add_image_size( 'four-column-thumb', 225, 140, true);
	add_image_size( 'three-column-thumb', 306, 170, true);
	add_image_size( 'two-column-thumb', 470, 230, true);
	
	
	add_action('admin_enqueue_scripts', 'my_admin_script');
}


function my_admin_script()
{
    wp_enqueue_script('my-admin', get_bloginfo('template_url').'/my-admin.js', array('jquery'));
}

/**
 * Custom breadcrumb trail arguments.
 */function breadcrumb_trail_args( $args ) {

	/* Change the text before the breadcrumb trail. */
	$args['before'] = __( 'You are here:', hybrid_get_textdomain() );

	/* Return the filtered arguments. */
	return $args;
}

function theme_register_sidebars() {
		
	/* Register the widgets template sidebar. */
	register_sidebar(
		array(
			'id' => 'primary',
			'name' => __( 'Primary Sidebar', hybrid_get_textdomain() ),
			'description' => __( 'Primary sidebar.', hybrid_get_textdomain() ),
			'before_widget' => '<div id="%1$s" class="widget %2$s widget-%2$s"><div class="widget-inside">',
			'after_widget' => '</div></div>',
			'before_title' => '<h3 class="widget-title title-small"><span>',
			'after_title' => '</span></h3>'
		)
	);	
	
	/* Register the widgets template sidebar. */
	register_sidebar(
		array(
			'id' => 'sidebar-page',
			'name' => __( 'Page Sidebar', hybrid_get_textdomain() ),
			'description' => __( 'Page sidebar.', hybrid_get_textdomain() ),
			'before_widget' => '<div id="%1$s" class="widget %2$s widget-%2$s"><div class="widget-inside">',
			'after_widget' => '</div></div>',
			'before_title' => '<h3 class="widget-title title-small"><span>',
			'after_title' => '</span></h3>'
		)
	);
	
	/* Register the widgets template sidebar. */
	register_sidebar(
		array(
			'id' => 'sidebar-subsidiary-1',
			'name' => __( 'Foot Sidebar #1', hybrid_get_textdomain() ),
			'description' => __( 'Foot Sidebar #1.', hybrid_get_textdomain() ),
			'before_widget' => '<div id="%1$s" class="widget %2$s widget-%2$s"><div class="widget-inside">',
			'after_widget' => '</div></div>',
			'before_title' => '<h3 class="widget-title"><span>',
			'after_title' => '</span></h3>'
		)
	);
	
	/* Register the widgets template sidebar. */
	register_sidebar(
		array(
			'id' => 'sidebar-subsidiary-2',
			'name' => __( 'Foot Sidebar #2', hybrid_get_textdomain() ),
			'description' => __( 'Foot Sidebar #2.', hybrid_get_textdomain() ),
			'before_widget' => '<div id="%1$s" class="widget %2$s widget-%2$s"><div class="widget-inside">',
			'after_widget' => '</div></div>',
			'before_title' => '<h3 class="widget-title"><span>',
			'after_title' => '</span></h3>'
		)
	);
	
	/* Register the widgets template sidebar. */
	register_sidebar(
		array(
			'id' => 'sidebar-subsidiary-3',
			'name' => __( 'Foot Sidebar #3', hybrid_get_textdomain() ),
			'description' => __( 'Foot Sidebar #3.', hybrid_get_textdomain() ),
			'before_widget' => '<div id="%1$s" class="widget %2$s widget-%2$s"><div class="widget-inside">',
			'after_widget' => '</div></div>',
			'before_title' => '<h3 class="widget-title"><span>',
			'after_title' => '</span></h3>'
		)
	);	

	/* Register the widgets template sidebar. */
	register_sidebar(
		array(
			'id' => 'sidebar-subsidiary-4',
			'name' => __( 'Foot Sidebar #4', hybrid_get_textdomain() ),
			'description' => __( 'Foot Sidebar #4.', hybrid_get_textdomain() ),
			'before_widget' => '<div id="%1$s" class="widget %2$s widget-%2$s"><div class="widget-inside">',
			'after_widget' => '</div></div>',
			'before_title' => '<h3 class="widget-title"><span>',
			'after_title' => '</span></h3>'
		)
	);
	
	/* Register the widgets template sidebar. */
	register_sidebar(
		array(
			'id' => 'sidebar-subsidiary-5',
			'name' => __( 'Foot Sidebar #5', hybrid_get_textdomain() ),
			'description' => __( 'Foot Sidebar #5.', hybrid_get_textdomain() ),
			'before_widget' => '<div id="%1$s" class="widget %2$s widget-%2$s"><div class="widget-inside">',
			'after_widget' => '</div></div>',
			'before_title' => '<h3 class="widget-title"><span>',
			'after_title' => '</span></h3>'
		)
	);

/* Register the widgets template sidebar. */
	register_sidebar(
		array(
			'id' => 'sidebar-single',
			'name' => __( 'Single post sidebar', hybrid_get_textdomain() ),
			'description' => __( 'Single post sidebar.', hybrid_get_textdomain() ),
			'before_widget' => '<div id="%1$s" class="widget %2$s widget-%2$s"><div class="widget-inside">',
			'after_widget' => '</div></div>',
			'before_title' => '<h3 class="widget-title title-small"><span>',
			'after_title' => '</span></h3>'
		)
	);	
	
}

/*-----------------------------------------------------------------------------------*/
/*  Meta box
/*-----------------------------------------------------------------------------------*/
add_filter( 'cmb_meta_boxes', 'meters_post_metaboxes' );
/**
 * Define the metabox and field configurations.
 *
 * @param  array $meta_boxes
 * @return array
 */
function meters_post_metaboxes( array $meta_boxes ) {

	// Start with an underscore to hide fields from custom fields list
	$prefix = '_meters_';
		
	$meta_boxes[] = array(
		'id'         => 'meters_post_metabox',
		'title'      => 'Post settings',
		'pages'      => array( 'post'), // Post type
		'context'    => 'normal',
		'priority'   => 'high',
		'show_names' => true, // Show field names on the left
		'fields'     => array(			
			array(
				'name'    => 'Trending story',
				'desc'    => 'Check to push this post to trending story.',
				'id'      => $prefix . 'trending_story',
				'type'    => 'checkbox',				
			),			
			array(
				'name'    => 'Featured story',
				'desc'    => 'Check to push this post to featured story.',
				'id'      => $prefix . 'featured_story',
				'type'    => 'checkbox',				
			),				
		
		),
	);
	
	
	return $meta_boxes;
}


add_action( 'init', 'meters_initialize_cmb_meta_boxes', 9999 );
/**
 * Initialize the metabox class.
 */
function meters_initialize_cmb_meta_boxes() {

	if ( ! class_exists( 'cmb_Meta_Box' ) )
		require_once trailingslashit( CVINCLUDES_DIR ) . 'custom-metabox/init.php';

}

?>